package com.game.ctrler
{
    import com.dusk.tool.KeyBoarder;
    import com.game.data.vo.KeyConfigVO;
    import com.game.manager.GameSceneManager;
    
    import config.Config;
    
    import flash.display.Stage;
    
    public class GameKeyInput
    {
        
        public function GameKeyInput()
        {
            super();
        }
        
        private var isStop:Boolean = false;
        private var _keyConfig:KeyConfigVO;
        private var _keyBoard:KeyBoarder;
        
        public function setKeyConfig(config:KeyConfigVO):void
        {
            _keyConfig = config;
        }
        
        public function setKeyboard(keyboard:KeyBoarder):void
        {
            _keyBoard = keyboard;
        }
        
        public function isPressUp():Boolean
        {
            return _keyBoard.isDown(_keyConfig.up);
        }
        
        public function isPressDown():Boolean
        {
            return _keyBoard.isDown(_keyConfig.down);
        }
        
        public function isWalkLeft():Boolean
        {
            return _keyBoard.isDown(_keyConfig.left) && _keyBoard.isUp(_keyConfig.right);
        }
        
        public function isWalkRight():Boolean
        {
            return _keyBoard.isDown(_keyConfig.right) && _keyBoard.isUp(_keyConfig.left);
        }
        
        public function isRunLeft():Boolean
        {
            return _keyBoard.isDoublePress(_keyConfig.left) && _keyBoard.isUp(_keyConfig.right);
        }
        
        public function isRunRight():Boolean
        {
            return _keyBoard.isDoublePress(_keyConfig.right) && _keyBoard.isUp(_keyConfig.left);
        }
        
        public function cancelRun():void
        {
            if (!_keyBoard)
            {
                return;
            }
            _keyBoard.cancelDoublePress(_keyConfig.left);
            _keyBoard.cancelDoublePress(_keyConfig.right);
        }
        
        public function isAttack():Boolean
        {
            return _keyBoard.isDown(_keyConfig.attack);
        }
        
        public function isJump():Boolean
        {
            return _keyBoard.isDown(_keyConfig.jump);
        }
        
        public function isJumpDown():Boolean
        {
            return _keyBoard.isDown(_keyConfig.down) && _keyBoard.isDown(_keyConfig.jump);
        }
        
        public function isSkill1():Boolean
        {
            return _keyBoard.isDown(_keyConfig.skill1);
        }
        
        public function isSkill2():Boolean
        {
            return _keyBoard.isDown(_keyConfig.skill2);
        }
        
        public function isSkill3():Boolean
        {
            return _keyBoard.isDown(_keyConfig.skill3);
        }
        
        public function isSkill4():Boolean
        {
            return _keyBoard.isDown(_keyConfig.skill4);
        }
        
        public function isSkill5():Boolean
        {
            return _keyBoard.isDown(_keyConfig.skill5);
        }
        
        public function isSkillSpecial():Boolean
        {
            return _keyBoard.isDown(_keyConfig.skillSpecial);
        }
        
        public function isUseSutra():Boolean
        {
            return _keyBoard.isDown(_keyConfig.useSutra);
        }
        
        public function isOpenBag():Boolean
        {
            return _keyBoard.isDown(_keyConfig.openBag);
        }
        
        public function isOpenSkill():Boolean
        {
            return _keyBoard.isDown(_keyConfig.openSkill);
        }
        
        public function isOpenPet():Boolean
        {
            return _keyBoard.isDown(_keyConfig.openPet);
        }
        
        public function isOpenSetting():Boolean
        {
            return _keyBoard.isDown(_keyConfig.openSetting);
        }
        
        public function addListenFunction(func:Function):void
        {
            _keyBoard.registerFunction(func);
        }
        
        public function removeListenFunction(func:Function):void
        {
            _keyBoard.removeFunction(func);
        }
        
        public function continueKeyboardControl():void
        {
            isStop = false;
        }
        
        public function stopKeyboardControl():void
        {
            isStop = true;
        }
        
        public function destroy():void
        {
            _keyBoard.destroy();
            _keyBoard = null;
        }
    }
}
